package com.principle.inversion.improve;

//定义一个接口
interface IReceiver {
    public String getInfo();
}

/**
 * @author xuehu
 * @date 2020/12/7 10:48
 * 依赖倒置原则 改进
 */

public class DependecyInversionImprove {

    public static void main(String[] args) {
        //客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeChat());
    }


}

//电子邮箱
class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件信息: hello world";
    }
}

//微信
class WeChat implements IReceiver {
    @Override
    public String getInfo() {
        return "微信信息: hello weChat";
    }
}


//方式2
class Person {
    public void receive(IReceiver iReceiver) {
        //这里我们是对接口的依赖
        System.out.println(iReceiver.getInfo());
    }
}
